<template>
  <div>
    <el-page-header content="管理员信息" @back="goBack">
    </el-page-header>
    <!-- 主页表格 -->
    <el-table
      :data="admins"
      style="width: 100%"
      :row-class-name="tableRowClassName">
      <el-table-column
        prop="id"
        label="管理员编号"
        width="100">
      </el-table-column>
      <el-table-column
        prop="nickname"
        label="管理员名字"
        width="100">
      </el-table-column>
      <el-table-column
        prop="gender"
        label="性别"
        width="100">
      </el-table-column>
      <el-table-column
        prop="datetime"
        label="账号创建时间"
        width="150">
        </el-table-column>
      <el-table-column
        prop="logintime"
        label="登陆时间"
        width="100">
      </el-table-column>
      <el-table-column
        prop="loginaddress"
        label="登录地址"
        width="100">
      </el-table-column>
       <el-table-column
        prop="role_name"
        label="职位"
        width="100">
      </el-table-column>
      <el-table-column
        prop="state"
        label="账号状态"
        width="100">
      </el-table-column> -->
    </el-table>
    <div class="block">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[3, 5, 10, 20]"
        :page-size="pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
      </el-pagination>
    </div>
  </div>
</template>

<script>
export default {
  data(){
    return {
        admins:[],
        currentsize:1,
        pagesize:3,
        // 分页
        currentPage: 1,
        total:0,
        pagesize:3,
    }
  },
  methods:{
    init(){
      let obj = {
        currentsize:this.currentPage, 
        pagesize:this.pagesize
      }
      this.$ajax({
        url:"admin/admin",
        method:"get",
        params:obj
      }).then(resp=>{
        // if(resp.data.status === 1){
        //   let admin = resp.data.message
        //   this.total = resp.data.totalPage
        //   admin.forEach(item=>{
        //     item.a_status=1?item.a_status="正常":item.a_status="禁用"
        //   })
        //   this.admins = admin;
        // }
        this.admins = resp.data.message;
        this.total = resp.data.totalPage;
      })
      
    },
    // 数据表格
    tableRowClassName({row, rowIndex}) {
      if (rowIndex%2 === 1) {
        return 'warning-row';
      } else{
        return 'success-row';
      }
    },
    // handleClick(row) {
    //   console.log(row);
    //   let status = 0;
    //   if(row.ca_status=="正常"){
    //     status=0
    //   }else{
    //     status=1
    //   }
    //   let obj = {
    //     id:row.ca_id, 
    //     status
    //   }
    //   this.$ajax({
    //     url:"after/carousel",
    //     method:"delete",
    //     params:obj
    //   }).then(resp=>{
    //     if(resp.data.status === 1){
    //       if(row.ca_status=="正常"){
    //         this.$message.error('已禁用');
    //       }else{
    //         this.$message({
    //           message: '启用成功',
    //           type: 'success'
    //         });
    //       }
    //       this.init();
    //     }
    //   })
    // },
    // 分页
    handleSizeChange(val) {
      this.pagesize = val
      this.init();
      // console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      this.init();
      // console.log(`当前页: ${val}`);
    },
    goBack() {
      this.$router.push("/")
    }
  },
  created(){
    this.init();
  }
}
</script>

<style scoped>
/* 数据表格 */
.el-table .warning-row {
    background: oldlace;
  }
.el-table .success-row {
  background: #f0f9eb;
}
</style>